package com.xiaoshuidi.cloud.framework.systemevent.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.xiaoshuidi.cloud.framework.systemevent.core.LeaseSystemEventConstants;
import com.xiaoshuidi.cloud.framework.systemevent.core.LeaseSystemEventConsumer;
import com.xiaoshuidi.cloud.framework.systemevent.core.LeaseSystemEventListener;
import com.xiaoshuidi.cloud.framework.systemevent.core.LeaseSystemEventProducer;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;

import java.util.List;

@AutoConfiguration
public class LeaseSystemEventListenerAutoConfiguration {
    @Bean(LeaseSystemEventConstants.CONSUMER)
    @ConditionalOnBean(LeaseSystemEventListener.class)
    public LeaseSystemEventConsumer leaseSystemEventConsumer(List<LeaseSystemEventListener> listeners, ObjectMapper objectMapper) {
        return new LeaseSystemEventConsumer(listeners, objectMapper);
    }

    @Bean
    public LeaseSystemEventProducer leaseSystemEventProducer() {
        return new LeaseSystemEventProducer();
    }
}
